import request, { Base_API } from '@/utils/request'

// 菜单接口
export const menu_request = {
  page(params) {
    return request({
      url: Base_API + '/function_list',
      method: 'get',
      params
    })
  },
  tree() {
    return request({
      url: Base_API + '/function_tree_search',
      method: 'get'
    })
  },
  add(data) {
    return request({
      url: Base_API + '/function_add',
      method: 'post',
      data
    })
  },
  edit(data) {
    return request({
      url: Base_API + '/function_edit',
      method: 'post',
      data
    })
  },
  // idList
  delete(idList) {
    return request({
      url: Base_API + '/function_delete',
      method: 'post',
      data: {
        idList
      }
    })
  }
}

// 图标接口
export const icon_request = {
  page(params) {
    return request({
      url: Base_API + '/icon_list',
      method: 'get',
      params
    })
  },
  list() {
    return request({
      url: Base_API + '/icon_list_search',
      method: 'get'
    })
  },
  add(data) {
    return request({
      url: Base_API + '/add_icon',
      method: 'post',
      data
    })
  },
  edit(data) {
    return request({
      url: Base_API + '/edit_icon',
      method: 'post',
      data
    })
  },
  // idList
  delete(idList) {
    return request({
      url: Base_API + '/delete_icon',
      method: 'post',
      data: {
        idList
      }
    })
  }
}

// 角色接口
export const role_request = {
  page(params) {
    return request({
      url: Base_API + '/role_list',
      method: 'get',
      params
    })
  },
  list() {
    return request({
      url: Base_API + '/role_list_search',
      method: 'get'
    })
  },
  add(data) {
    return request({
      url: Base_API + '/role_add',
      method: 'post',
      data
    })
  },
  edit(data) {
    return request({
      url: Base_API + '/role_edit',
      method: 'post',
      data
    })
  },
  // idList
  delete(idList) {
    return request({
      url: Base_API + '/role_delete',
      method: 'post',
      data: {
        idList
      }
    })
  },
  // role_function
  getRoleBindMenu(id) {
    return request({
      url: Base_API + '/role_function',
      method: 'get',
      params: {
        id
      }
    })
  },
  roleBindMenu(data) {
    return request({
      url: Base_API + '/role_grant_function',
      method: 'post',
      data
    })
  }
}

// 用户接口
export const user_request = {
  page(params) {
    return request({
      url: Base_API + '/user_list',
      method: 'get',
      params
    })
  },
  add(data) {
    return request({
      url: Base_API + '/user_add',
      method: 'post',
      data
    })
  },
  edit(data) {
    return request({
      url: Base_API + '/user_edit',
      method: 'post',
      data
    })
  },
  // idList
  delete(idList) {
    return request({
      url: Base_API + '/user_delete',
      method: 'post',
      data: {
        idList
      }
    })
  },
  changeStatus(data) {
    return request({
      url: Base_API + '/user_edit_status',
      method: 'post',
      data
    })
  },
  initPassword(id) {
    return request({
      url: Base_API + '/user_edit_status',
      method: 'post',
      data: {
        id
      }
    })
  },
  getRoleBindMenu(id) {
    return request({
      url: Base_API + '/user_role',
      method: 'get',
      params: {
        id
      }
    })
  },
  userBindRole(data) {
    return request({
      url: Base_API + '/user_grant_role',
      method: 'post',
      data
    })
  }
}
